package vip.finance.makemoney.common.utils;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yangbin
 * @since 2023-03-01
 */
@Data
public class PageVo<T> {
    /**
     * 总数
     */
    protected long total;
    /**
     * 排序
     */
    protected List<T> records;
    /**
     * 页码
     */
    protected int current;
    /**
     * 每页结果数
     */
    protected int size;

    public PageVo(int current, int size) {
        this.current = current;
        this.size = size;
        this.records = new ArrayList<>();
    }

    public static <T> PageVo<T> convert(IPage<T> pageInfo) {
        if (null == pageInfo) {
            return null;
        } else {
            PageVo<T> pageInfoDto = new PageVo<>((int) pageInfo.getCurrent(), (int) pageInfo.getSize());
            pageInfoDto.setRecords(pageInfo.getRecords());
            pageInfoDto.setTotal(pageInfo.getTotal());
            return pageInfoDto;
        }
    }
}
